from math import*
a=int(input("Введите число: "))
C=[]
if a>=1000 and a<=9999:
    a1=a//1000
    a2=a//100
    a3=a//10
    a4=a%10%100
    a5=a%1000
    a6=a%100
    a7=a//10%100
    a8=a%100//10
    a9=a//100%10
    B=[a,a1,a2,a3,a4,a5,a6,a7,a8,a9]

    for i in B:
       prime=True
       m=2
       while m<=sqrt(i):
           if i%m==0:
               prime=False
               break
           m+=1
       if prime:
            C.append(i)

    if len(C)>0:
        print(max(C))
    else:
        print("0")
    

else:
    print("0")
